package com.ruoyi.forum.service;

import com.ruoyi.forum.api.vo.UserDetail;
import com.ruoyi.forum.dependency.AuthService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description:用户服务扩展
 * @Author: Hoda
 * @Date: Create in 2019-09-04
 * @Modified By:
 * @Modified Date:
 */
@Service
public class AuthServiceExt {

    @Autowired
    private AuthService authService;

    /**
     * 根据用户ID列表查询用户信息，并返回map
     *
     * @param uidList
     * @return
     */
    public Map<String, UserDetail> getUserMapByUidList(List<String> uidList) {
        if (CollectionUtils.isEmpty(uidList)) {
            return new HashMap<>();
        }
        List<UserDetail> userList = authService.getUserList(uidList);
        return userList.stream()
                .collect(Collectors.toMap(UserDetail::getUid, Function.identity()));
    }

    /**
     * 根据uid获取用户详细信息
     *
     * @param uid
     * @return
     */
    public UserDetail getUserDetail(String uid) {
        UserDetail userDetailResult = authService.getUserDetail(uid);
        return userDetailResult;
    }
}
